
package elementos;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;

public class Ranking implements Serializable{
    private class Rank implements Serializable, Comparable {
        private String id;
        private float time;

        public Rank(String id, float time) {
            this.id = id;
            this.time = time;
        }

        public String getId() {
            return id;
        }

        public float getTime() {
            return time;
        }
        
        public String toString(){
            String s="";
            s+="Jugador: "+id+" , Tiempo: "+time;
            return s;
        }

        @Override
        public int compareTo(Object t) {
            Rank o = (Rank)t;
            if(o.time==time) return 0;
            if(o.time<time) return 1;
            return -1;
        }
        
    }
    
    private ArrayList<Rank> scores;
    
    public Ranking(){
        scores= new ArrayList<Rank>();
    }
    
    public ArrayList getScores(){
        return scores;  
    }
    
    public void addScore(String id, float tiempo){
        scores.add(new Rank(id,tiempo));
        Collections.sort(scores);
    }
    
    public String[] getScoresToString(){
        String []vec= new String[scores.size()];
        for(int i=0;i<scores.size();i++){
            vec[i]=((Rank)scores.get(i)).toString();
        }
        return vec;
    }
    
    public String toString(){
        String s="";
        for(int i=0;i<scores.size();i++){
            s+=((Rank)scores.get(i)).toString()+"\n";
        }
        return s;
    }
    
}
